'''
Created on Nov 20, 2011

@author: poco153
'''
import wx
import databaseInterface

class mainGrid(wx.Frame):
    dateInput = 0;
    jobNumInput = 0
    jobDescInput = 0
    hoursInput = 0
    db = 0
    def __init__(self, parent, title, database):
        super(mainGrid, self).__init__(parent, title=title, size=(600, 125))
        
        mainGrid.db = database
        
        self.InitUI()
        self.Centre()
        self.Show()
    
    def InitUI(self):
        panel = wx.Panel(self)
        
        hbox = wx.BoxSizer(wx.HORIZONTAL) 
        
        fgs = wx.FlexGridSizer(2, 5, 9, 25)
        
        dateLabel = wx.StaticText(panel, label="Date:")
        jobNumLabel = wx.StaticText(panel, label="Job Number:")
        jobDescLabel = wx.StaticText(panel, label="Job Description:")
        hoursLabel = wx.StaticText(panel, label="Hours:")
        spacer = wx.StaticText(panel)
        
        mainGrid.dateInput = wx.TextCtrl(panel)
        mainGrid.jobNumInput = wx.TextCtrl(panel)
        mainGrid.jobDescInput = wx.TextCtrl(panel)
        mainGrid.hoursInput = wx.TextCtrl(panel)
        
        saveButton = wx.Button(panel, label="Save")
        self.Bind(wx.EVT_BUTTON, self.onSaveClick, saveButton)
        
        
        fgs.AddMany([(dateLabel), (jobNumLabel), (jobDescLabel), (hoursLabel), (spacer), (mainGrid.dateInput, 1, wx.EXPAND), (mainGrid.jobNumInput, 1, wx.EXPAND), (mainGrid.jobDescInput, 1, wx.EXPAND), (mainGrid.hoursInput, 1, wx.EXPAND), (saveButton, 1, wx.EXPAND)])
        
        fgs.AddGrowableRow(2, 1)
        
        hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=15)
        panel.SetSizer(hbox)
        
    def onSaveClick(self, event):
        #Save button has been clicked!
        mainGrid.db.addNewRow(mainGrid.dateInput.GetString(0, mainGrid.dateInput.GetLastPosition()), mainGrid.jobNumInput.GetString(0, mainGrid.jobNumInput.GetLastPosition()), mainGrid.jobDescInput.GetString(0, mainGrid.jobDescInput.GetLastPosition()), mainGrid.hoursInput.GetString(0, mainGrid.hoursInput.GetLastPosition()))